import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '../layout' //布局页
import notFoundRoute from '../views/error/404.vue'

Vue.use(VueRouter)

//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    redirect: '/index',
    component: Layout,
    children: [
      {
        path: '/index',
        component: () => import('@/views/index/index.vue'),
        meta: {
          title: "首页",
          icon: 'el-icon-s-home',
        }
      },
    ]
  },
  {
    path: '/account',
    component: Layout,
    redirect: '/account/info',
    meta: {
      title: "账户管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'info',
        name: 'info',
        component: () => import('@/views/account/info/index.vue'),
        meta: {
          title: "基本信息",
        }
      },
      {
        path: 'config',
        name: 'config',
        component: () => import('@/views/account/config/index.vue'),
        meta: {
          title: "应用配置",
        }
      },
      // 登录密码
      {
        path: 'loginPassword',
        component: () => import('@/views/account/loginPassword/index.vue'),
        meta: {
          title: "登录密码",
        }
      },
        // 支付密码
        {
          path: 'payPassword',
          component: () => import('@/views/account/payPassword/index.vue'),
          meta: {
              title: "支付密码",
          }
        },
        // 登录记录
      {
        path: 'loginRecord',
        component: () => import('@/views/account/loginRecord/index.vue'),
        meta: {
          title: "登录记录",
        }
      }
    ]
  },
  /**
   * 财务管理
   * 资金记录、转账/提现、申请提U、商户互转、批量提现、统计报表
   */
  {
    path: '/finance',
    component: Layout,
    redirect: '/finance/withdrawManagement',
    meta: {
      title: "财务管理",
      icon: 'el-icon-s-finance',
    },
    children: [
      {
        path: 'withdrawManagement',
        component: () => import('@/views/finance/fundRecord/index.vue'),
        meta: {
          title: "资金记录",
        }
      },
      {
        path: 'transfer',
        component: () => import('@/views/finance/transfer/index.vue'),
        meta: {
          title: "转账/提现",
        }
      },
      {
        path: 'applyU',
        component: () => import('@/views/finance/applyU/index.vue'),
        meta: {
          title: "申请提U",
        }
      },
      {
        path: 'merchantTransfer',
        component: () => import('@/views/finance/merchantTransfer/index.vue'),
        meta: {
          title: "商户互转",
        }
      },
      {
        path: 'batchWithdraw',
        component: () => import('@/views/finance/batchWithdraw/index.vue'),
        meta: {
          title: "批量提现",
        }
      },
      {
        path: 'statisticalReport',
        hidden: true,
        component: () => import('@/views/finance/statisticalReport/index.vue'),
        meta: {
          title: "统计报表",
        }
      }
    ]
  },
    // 代收管理、代收订单
  {
    path: '/collection',
    component: Layout,
    redirect: '/collection/collectionManagement',
    meta: {
      title: "代收管理",
      icon: 'el-icon-s-order',
    },
    children: [
        {
          path: 'collectionManagement',
          name: 'collectionManagement',
          component: () => import('@/views/collection/collectionManagement/index.vue'),
          meta: {
            title: "代收订单",
          }
        }
   ]
  },
    // 代付管理、代付订单
  {
    path: '/payment',
    component: Layout,
    redirect: '/payment/paymentManagement',
    meta: {
      title: "代付管理",
      icon: 'el-icon-s-order',
    },
    children: [
      {
        path: 'paymentManagement',
        name: 'paymentManagement',
        component: () => import('@/views/payment/paymentManagement/index.vue'),
        meta: {
          title: "代付订单",
        }
      }
    ]
  },
    // 提现订单
  {
    path: '/withdraw',
    component: Layout,
    redirect: '/withdraw/withdrawManagement',
    meta: {
      title: "提现管理",
      icon: 'el-icon-s-order',
    },
    children: [
      {
        path: 'withdrawManagement',
        name: 'withdrawManagement',
        component: () => import('@/views/withdraw/withdrawManagement/index.vue'),
        meta: {
          title: "提现订单",
        }
      }
    ]
  },
    // 应用 导出记录、创建收款
  {
    path: '/application',
    component: Layout,
    redirect: '/application/exportRecord',
    meta: {
      title: "其他应用",
      icon: 'el-icon-s-order',
    },
    children: [
      {
        path: 'exportRecord',
        component: () => import('@/views/application/exportRecord/index.vue'),
        meta: {
          title: "导出记录",
        },
      },
      {
        path: 'createCollection',
        name: 'createCollection',
        component: () => import('@/views/application/createCollection/index.vue'),
        meta: {
          title: "创建收款",
        },
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/Login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
  {
    path: '/404',
    meta: {
      title: "页面走丢了",
    },
    component: notFoundRoute,
    hidden: true //导航菜单忽略选项
  },
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
